{% extends 'layouts/base.html' %}
{% block content %}

<div class="row">
    <div class="col-xs-12">
        <!-- PAGE CONTENT BEGINS -->        
        <div class="row">
            <div class="col-xs-12">
                <form action="{{ url('backend/order/index')}}" class="center form-inline clearfix form-actions" role="form" method="post" enctype="multipart/form-data">
                    <div class="row-fluid" style="margin-bottom: 10px;">
                            <div class="form-group{% if errors['tel'] is not empty %} has-error{%endif%}">
                                <label for="tel" class="col-xs-12 col-sm-3 col-md-4 control-label no-padding-right">客户电话</label>
                                <div class="col-xs-12 col-sm-7">
                                    <span class="input-icon input-icon-right">
                                        <input type="text" id="title" placeholder="客户电话" name="tel" class="span4 input-md" value="{{tel}}" />
                                    </span>
                                </div>
                                <div class="help-block col-xs-12 col-sm-reset inline"> {% if errors['tel'] is not empty %}{{errors['tel']}}{% else %} {%endif%} </div>
                            </div>

                            <div class="form-group{% if errors['number'] is not empty %} has-error{%endif%}">
                                <label for="number" class="col-xs-12 col-sm-3 col-md-4 control-label no-padding-right">订单号</label>
                                <div class="col-xs-12 col-sm-7">
                                    <span class="input-icon input-icon-right">
                                        <input type="text" id="title" placeholder="订单号" name="number" class="span4 input-md" value="{{number}}" />
                                    </span>
                                </div>
                                <div class="help-block col-xs-12 col-sm-reset inline"> {% if errors['number'] is not empty %}{{errors['number']}}{% else %} {%endif%} </div>
                            </div>

                            <div class="form-group{% if errors['account'] is not empty %} has-error{%endif%}">
                                <label for="account" class="col-xs-12 col-sm-3 col-md-4 control-label no-padding-right">联系人</label>
                                <div class="col-xs-12 col-sm-7">
                                    <span class="input-icon input-icon-right">
                                        <input type="text" id="title" placeholder="用户账号" name="account" class="span4 input-md" value="{{account}}" />
                                    </span>
                                </div>
                                <div class="help-block col-xs-12 col-sm-reset inline"> {% if errors['account'] is not empty %}{{errors['account']}}{% else %} {%endif%} </div>
                            </div>
                            <div class="center-block row-fluid" style="display:inline-block;margin-left:70px;">
                              <button class="btn btn-info" type="submit">
                                  <i class="ace-icon fa fa-check bigger-110"></i>
                                  搜索
                              </button>
                          </div>
                    </div>

                      


                </form>
            </div>


            <div class="col-xs-12">
                <div class="col-xs-12" style="margin-bottom: 10px;">
                    <label>状态选择</label>
                    <select name="state" onchange="parent.location.href = options[selectedIndex].value">
                        <option value="{{ url('backend/order/index/')}}" {% if state == null and place == null %} selected="selected" {%endif%}>全选</option>
                        <option value="{{ url('backend/order/index/')}}/state/0/place/1" {% if state == 0 and place == 1 %} selected="selected" {%endif%}>未支付</option>

                        <option value="{{ url('backend/order/index/')}}/state/0/place/2"  {% if state == 0 and place == 2 %} selected="selected" {%endif%}>未确认</option>


                        <option value="{{ url('backend/order/index/')}}/state/1/place/1"  {% if state == 1 and place == 1 %} selected="selected" {%endif%}>已支付</option>

                        <option value="{{ url('backend/order/index/')}}/state/1/place/2"  {% if state == 1 and place == 2 %} selected="selected" {%endif%}>已确认</option>


                        <option value="{{ url('backend/order/index/')}}/state/2"  {% if state == 2 %} selected="selected" {%endif%}>已派工</option>

                        <option value="{{ url('backend/order/index/')}}/state/3"  {% if state == 3 %} selected="selected" {%endif%}>完成</option>

                        <option value="{{ url('backend/order/index/')}}/state/-2"  {% if state == -2 %} selected="selected" {%endif%}>已退款</option>

                    </select> 
                </div>
                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th class="center">
                                <label class="position-relative">
                                    <input type="checkbox" class="ace" />
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th><a href="{{ url('curr_url', {'sort':'order_id'})}}">编号</a></th>
                            <th><a href="{{ url('curr_url', {'sort':'order_number'})}}">订单号</a></th>
                            <th><a href="{{ url('curr_url', {'sort':'order_place'})}}">渠道</a></th>
                            <th><a href="{{ url('curr_url', {'sort':'createtime'})}}">下单时间</a></th>
                            <th><a href="{{ url('curr_url', {'sort':'start_address'})}}">套餐类型</a></th>
                            <th>联系人</th>
                            <th>手机</th>
                            <th><a href="{{ url('curr_url', {'sort':'carrydate'})}}">搬运日期</a></th>
                            <th><a href="{{ url('curr_url', {'sort':'must_price'})}}">应付款</a></th>
                            <th>已支付</th>
                            <th>优惠金额</th>
                            <th>确认尾款</th>
                            <th>订单状态</th> 
                            <th>操作</th>
                        </tr>
                    </thead>

                    <tbody>


                        {% for row in result %}
                        <tr>
                            <td class="center">
                                <label class="position-relative">
                                    <input name="dels[]" value="{{row.order_id}}" type="checkbox" class="ace" />
                                    <span class="lbl"></span>
                                </label>
                            </td>

                            <td> {{row.order_id}} </td>
                            <td> {{row.order_number}} </td>
                            <td> {% if row.order_place == 1 %} 
                                微信客服端
                                {%else%}
                                后台创建
                                {%endif%}
                            </td>
                            <td> {{row.createtime|date('Y-d-m H:i:s')}} </td>
                            {% if row.meal_type == 0 %}
                            <td>非套餐 </td>
                            {%else%}
                            <td> 套餐 </td>
                            {%endif%}
                            <td> {{row.client_name}} </td>
                            <td> {{row.client_phone}} </td>
                            <td> {{row.carrydate|date('Y-d-m')}} </td>
                            <td> {{row.must_price}} </td>
                            <td> {{row.already_price}} </td>
                            <td> {{row.card_fee}} </td>
                            <td> {{row.final_payment}} </td>
                            {% if row.order_state == 0 %}
                            {%if row.order_place == 1%}
                            <td>未支付</td>
                            {%else%}
                            <td>未确认</td>
                            {%endif%}
                            {%elseif row.order_state == 1%}
                            {%if row.order_place == 1%}
                            <td>已支付</td>
                            {%else%}
                            <td>已确认</td>
                            {%endif%}
                            {%elseif row.order_state == 2%}
                            <td>已派工</td>
                            {%elseif row.order_state == 3%}
                            <td>完成</td>
                            {%elseif row.order_state == -2%}
                            <td>已退款</td>
                            {%endif%}
                            {% if row.order_state == 0 %} 

                            <td>
                                <a href="{{ url('backend/order/info')}}/order_id/{{row.order_id}}">确认订单</a>

                                <button class="btn-link" data-toggle="modal" data-target="#deleteOrder">
                                    删除
                                </button>
                                <!-- 模态框（Modal） -->
                                <div class="modal fade" id="deleteOrder" tabindex="-1" role="dialog" 
                                     aria-labelledby="myModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" 
                                                        data-dismiss="modal" aria-hidden="true">
                                                    &times;
                                                </button>
                                                <h4 class="modal-title" id="deleteOrderLabel">
                                                    注意
                                                </h4>
                                            </div>
                                            <div class="modal-body">
                                                确认是否删除
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" 
                                                        data-dismiss="modal">否
                                                </button>
                                                <a href='{{url('backend/order/del', {'order_id':row.order_id})}}' class="btn btn-primary">
                                                    是
                                                </a>
                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal -->


                            </td>
                            {%elseif row.order_state == 1%}
                            <td><a href="{{ url('backend/order/info')}}/order_id/{{row.order_id}}">派工</a></td>
                            {%elseif row.order_state == 2%}
                            <td><a href="{{ url('backend/order/info')}}/order_id/{{row.order_id}}">结单</a></td>
                            {%elseif row.order_state == 3%}
                            <td><a href="{{ url('backend/order/info')}}/order_id/{{row.order_id}}">查看</a></td>
                            {%elseif row.order_state == -2%}
                            <td><a href="{{ url('backend/order/info')}}/order_id/{{row.order_id}}">查看</a></td>
                            {%endif%}
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>

                <div class="text-right">
                    <span>
                        <label class="">总额度：</label>
                        {% set sum = 0 %}
                        {% for v in result %}
                        {% set sum = sum + v.must_price %}
                        {% endfor %}
                        <label class="red">
                            {{sum}}
                        </label>
                        <label class="">元</label>
                    </span>&nbsp; &nbsp;

                    <span>
                        <label class="">已付：</label>
                        {% set sum = 0 %}
                        {% for v in result %}
                        {% set sum = sum + v.already_price %}
                        {% endfor %}
                        <label class="red">
                            {{sum}}
                        </label>
                        <label class="">元</label>
                    </span>&nbsp; &nbsp;
                    
                    <span>
                        <label class="">优惠总额：</label>
                        {% set sum = 0 %}
                        {% for v in result %}
                        {% set sum = sum + v.card_fee %}
                        {% endfor %}
                        <label class="red">
                            {{sum}}
                        </label>
                        <label class="">元</label>
                    </span>&nbsp; &nbsp;

                    <span>
                        <label class="">未付：</label>
                        {% set sum = 0 %}
                        {% for v in result %}
                        {% set sum = sum + v.must_price - v.already_price - v.card_fee%}
                        {% endfor %}
                        {%if sum < 0 %}
                        {%set sum = 0 %}
                        {%endif %}
                        <label class="red">
                            {{sum}}
                        </label>
                        <label class="">元</label>
                    </span>&nbsp;
                </div>

                <div class="row">
                    <div class="col-xs-6 col-xs-offset-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <ul class="pagination">
                                {{pagestr | raw}}
                            </ul>
                        </div>
                    </div>
                </div>


            </div><!-- /.span -->



        </div><!-- /.row -->


    </div>
</div>

<!-- inline scripts related to this page -->
{% endblock %}
